<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			function TreeNode(val, left, right) {
				this.val = (val === undefined ? 0 : val)
				this.left = (left === undefined ? null : left)
				this.right = (right === undefined ? null : right)
			}
			let r = new TreeNode(1,
				new TreeNode(2,
					new TreeNode(4, null, null),
					new TreeNode(5, null, null)),
				new TreeNode(3,
					new TreeNode(6, null, null),
					new TreeNode(7, null, null)));
			var binaryTreePaths = function(root) {
				const paths = [];
				const construct_paths = (root, path) => {
					if (root) {
						path += root.val.toString();
						if (root.left === null && root.right === null) { // 当前节点是叶子节点
							paths.push(path); // 把路径加入到答案中
						} else {
							path += "->"; // 当前节点不是叶子节点，继续递归遍历
							construct_paths(root.left, path);
							construct_paths(root.right, path);
						}
					}
				}
				construct_paths(root, "");
				return paths;
			};
			console.log(binaryTreePaths(r));
		</script>
	</body>
</html>
